<html>
<head>
    <title>OpenX Schema Analysis Utilities</title>
    <link rel="stylesheet" type="text/css" href="css/upgrade.css"/>

    <!--script type="text/javascript" src="schema.js"></script>
    <script type="text/javascript" src="../../lib/xajax/xajax_js/xajax.js"></script>
    <script type="text/javascript">
        window.setTimeout(function () { if (!xajaxLoaded) { alert('Error: the xajax Javascript file could not be included. Perhaps the URL is incorrect?\nURL: ../lib/xajax/xajax_js/xajax.js'); } }, 6000);
    </script-->

</head>
<body>
<div class="tablediv" style="background: #FFFFFF;">
    <h2>OpenX Schema Analysis Utilities</h2>
    <?php
        foreach ($aDisplay AS $k => $v)
        {
    ?>
    <table class="tablemain" style="border:1px black double;margin-top:10px;">
    <?php
        if (isset($v['error']))
        {
    ?>
        <tr>
            <td class="tablebody" style="background:lightgray"><?php echo htmlspecialchars($v['error']); ?></td>
        </tr>
    <?php
        }
        else
        {
    ?>
        <tr>
            <td class="tablebody" colspan="9"><?php echo htmlspecialchars($v['query']); ?></td>
        </tr>
        <tr>
            <th class="textmini">table</th>
            <th class="textmini">ref</th>
            <th class="textmini">type</th>
            <th class="textmini">rows</th>
            <th class="textmini">key</th>
            <th class="textmini">key_len</th>
            <th class="textmini">possible_keys</th>
            <th class="textmini">select_type</th>
            <th class="textmini">extra</th>
        </tr>
      <?php
            foreach ($v['result'] AS $rk => $rv)
            {
                $styleType =  '';
                $stylePoss =  '';
                if ($rv['rows']>10)
                {
                    switch (trim($rv['type']))
                    {
                        case 'ALL':
                        case 'index_merge':
                        case 'index':
                        case 'index_subquery':
                        case 'range':
                        case 'unique_subquery':
                            if ($rv['rows']>10)
                            {
                                $styleType =  'style="background:lightpink"';
                            }
                            break;
                    }
                    switch (trim($rv['possible_keys']))
                    {
                        case null:
                            $stylePoss =  'style="background:lightpink"';
                            break;
                    }
                }
        ?>
                <tr>
                    <td class="tablebody"><?php echo $rv['table']; ?></td>
                    <td class="tablebody"><?php echo $rv['ref']; ?></td>
                    <td class="tablebody" <?php echo $styleType; ?>><?php echo $rv['type']; ?></td>
                    <td class="tablebody"><?php echo $rv['rows']; ?></td>
                    <td class="tablebody"><?php echo $rv['key']; ?></td>
                    <td class="tablebody"><?php echo $rv['key_len']; ?></td>
                    <td class="tablebody" <?php echo $stylePoss; ?>><?php echo $rv['possible_keys']; ?></td>
                    <td class="tablebody"><?php echo $rv['select_type']; ?></td>
                    <td class="tablebody"><?php echo $rv['extra']; ?></td>

                </tr>
    <?php
            }
        }
    ?>
    </table>
    <?php
        }
    ?>
</body>
</html>